package org.ratingviewer.ui.action;

import java.awt.Window;
import java.awt.event.ActionEvent;

import javax.swing.*;

public class ActionExit extends AbstractResourcedAction {

	private static final long serialVersionUID = 1L;

	private final Window window;

	public ActionExit(Window window, JComponent shortcutHandler) {
		super("item.exit", shortcutHandler);

		if (window == null)
			throw new IllegalArgumentException("Window can't be null.");
		this.window = window;
	}

	public ActionExit(Window window) {
		this(window, null);
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				window.dispose();
			}
		});
	}

}
